package com.zx.kitchen.index.common.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zx.kitchen.index.R;
import com.zx.kitchen.index.common.entity.GoodsReportDishesBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/5.
 */

public class GoodsReportDishListAdapter extends BaseAdapter {

    private List<GoodsReportDishesBean> objects = new ArrayList<GoodsReportDishesBean>();

    private Context context;
    private LayoutInflater layoutInflater;

    public GoodsReportDishListAdapter(Context context, List<GoodsReportDishesBean> objects) {
        this.context = context;
        this.objects = objects;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public GoodsReportDishesBean getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.adapter_goods_report_dishlist, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((GoodsReportDishesBean) getItem(position), (ViewHolder) convertView.getTag(), convertView, position);
        return convertView;
    }

    private void initializeViews(GoodsReportDishesBean object, ViewHolder holder, View convertView, int position) {
        holder.dishName.setText(object.getName());
        holder.dishStandard.setText(object.getBrand() + "  " + object.getStandard());
        holder.dishNum.setText(object.getNum());
        holder.dishTotal.setText(object.getTotal());
    }

    protected class ViewHolder {
        private TextView dishName;
        private TextView dishNum;
        private TextView dishTotal;
        private TextView dishStandard;

        public ViewHolder(View view) {
            dishName = (TextView) view.findViewById(R.id.dish_name);
            dishNum = (TextView) view.findViewById(R.id.dish_num);
            dishTotal = (TextView) view.findViewById(R.id.dish_total);
            dishStandard = (TextView) view.findViewById(R.id.dish_standard);
        }
    }

}
